package exam.beike.S2;


import java.util.Scanner;

public class Main {

    public static int T;
    public static int left;
    public static int right;
    public static int[] res = new int[1000001];


    public static void main(String[] args) {
        prepare();
        Scanner sc = new Scanner(System.in);
        T = sc.nextInt();
        for (int i=0; i<T; ++i) {
            left = sc.nextInt();
            right = sc.nextInt();
            solution();
        }
    }

    public static void prepare() {
        for (int i=1; i<1000001; ++i) {
            int S = getS(i);
            int num = i % S == 1 ? 1 : 0;
            res[i] = res[i-1] + num;
        }
    }

    public static void solution() {
        System.out.println(res[right]-res[left-1]);
    }

    public static int getS(int n) {
        int S = 0;
        while (n > 0) {
            S += (n % 10);
            n /= 10;
        }
        return S;
    }
}
